<template>
  <div>
    <van-cell title="搜索历史">
      <template>
        <van-icon v-if="!del" name="delete-o" @click="del=true" />
        <div v-else>
          <span @click="history.splice(0)">全部删除</span>
          <span style="margin-lefy:7px" @click="del=false">完成</span>
        </div>
      </template>
    </van-cell>

    <van-cell v-for="item in history" :key="item" :title="item" @click="clickrem(item)">
      <template v-if="del">
        <van-icon name="close" />
      </template>
    </van-cell>
  </div>
</template>

<script>
export default {
  props: {
    history: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      del: false
    }
  },

  created() {

  },

  methods: {
    clickrem(value) {
      if (this.del) {
        const index = this.history.indexOf(value)
        this.history.splice(index, 1)
      } else {
        this.$emit('onSearch', value)
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
